import { ref, computed, reactive } from 'vue'
import { defineStore } from 'pinia'
import { getUserInfo, removeUserInfo } from '@/utils/storage.ts'
export const useUserStore = defineStore('user', () => {
    const userInfo: any = reactive({
        userAccount: '', //账号
        userName: '',//姓名
        updatePassword: '',//是否需要更新密码
        userEmail: '',//邮箱
        userPhone: '',//手机号
        userStatusStr: '',//用户状态
        branchOrgName: '',//部门名称
        branchOrgCode: ''//部门编码
    })
    const setUserInfo = (info: any) => {
        userInfo.userAccount = info.userAccount
        userInfo.userName = info.userName
        userInfo.updatePassword = info.updatePassword
        userInfo.userEmail = info.userEmail
        userInfo.userPhone = info.userPhone
        userInfo.userStatusStr = info.userStatusStr
        userInfo.branchOrgName = info.branchOrgName
        userInfo.branchOrgCode = info.branchOrgCode
    }
    const clearUserInfo = () => {
        removeUserInfo()
        userInfo.userAccount = ''
        userInfo.userName = ''
        userInfo.updatePassword = ''
        userInfo.userEmail = ''
        userInfo.userPhone = ''
    }
    return {
        userInfo,
        setUserInfo,
        clearUserInfo
    }
}, {
    persist: true, // 开启持久化存储
})